package com.mc.lp.database.entity.type;

import javax.persistence.AttributeConverter;
/*
 * @author aphanda
 * @date Sep 21, 2014
 * @time 2:17:32 AM
 */

//@Converter(autoApply = true)
public class TermTypeConverter implements AttributeConverter<TermType, Integer> {

 
 public Integer convertToDatabaseColumn(TermType termType) {
  switch (termType) {
  case FIRST:
   return 1;
  case SECOND:
   return 2;
  case THIRD:
   return 3;
  case FOURTH:
   return 4;
  default:
   throw new IllegalArgumentException("Unknown value: " + termType);
  }
 }

 public TermType convertToEntityAttribute(Integer dbData) {
  switch (dbData) {
  case 1:
   return TermType.FIRST;
  case 2:
   return TermType.SECOND;
  case 3:
   return TermType.THIRD;
  case 4:
   return TermType.FOURTH;
  default:
   throw new IllegalArgumentException("Unknown value: " + dbData);
  }
 }

}
